package com.fanx.content.api;

import com.fanx.base.execption.ValidationGroups;
import com.fanx.base.model.PageParams;
import com.fanx.base.model.PageResult;
import com.fanx.content.model.dto.AddCourseDto;
import com.fanx.content.model.dto.CourseBaseInfoDto;
import com.fanx.content.model.dto.EditCourseDto;
import com.fanx.content.model.dto.QueryCourseParamsDto;
import com.fanx.content.model.po.CourseBase;
import com.fanx.content.service.CourseBaseInfoService;
import com.fanx.content.util.SecurityUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @deprecated 课程信息编辑接口
 */
@Api(value = "课程信息管理接口",tags = "课程信息管理接口")
@RestController
public class CourseBaseInfoController {

    @Autowired
    CourseBaseInfoService courseBaseInfoService;

    @ApiOperation("课程分页查询接口")
    @PreAuthorize("hasAnyAuthority('xc_teachmanager_course_list')")//指定权限标识符
    @PostMapping("/course/list")
    public PageResult<CourseBase> list(PageParams pageParams, @RequestBody(required = false) QueryCourseParamsDto queryCourseParams){
        //当前登录用户
        SecurityUtil.XcUser user = SecurityUtil.getUser();
        //用户所属机构id
        Long companyId = null;
        if(StringUtils.isNotEmpty(user.getCompanyId())){
            companyId = Long.parseLong(user.getCompanyId());
        };
        return courseBaseInfoService.queryCourseBaseList(companyId,pageParams, queryCourseParams);
    }

    @ApiOperation("新增课程接口")
    @PostMapping("/course")//@Validated表示校验参数
    public CourseBaseInfoDto createCourseBase(@RequestBody @Validated(ValidationGroups.Update.class) AddCourseDto addCourseDto){
        //获取用户的机构id
        Long companyId=1232141425L;
       // int i=1/0;
        return courseBaseInfoService.createCourseBase(companyId,addCourseDto);

    }

    @ApiOperation("根据课程id查询接口")
    @GetMapping("/course/{courseId}")
    public CourseBaseInfoDto getCourseBaseById(@PathVariable Long courseId){
        return courseBaseInfoService.getCourseBaseInfo(courseId);
    }

    @ApiOperation("修改课程")
    @PutMapping("/course")
    public CourseBaseInfoDto modifyCourseBase(@RequestBody @Validated(ValidationGroups.Update.class) EditCourseDto editCourseDto){
        //获取用户的机构id
        Long companyId=1232141425L;
        return courseBaseInfoService.updateCourseBase(companyId,editCourseDto);
    }




}
